home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 007 (1987-02-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 007 (1987-02-15)(Ossowski, Stefan)(DE)(PD).adf / C Compiler / cmain.c < prev    next >
C/C++ Source or Header  |  1987-03-04  |  3KB  |  110 lines

  1. #include        <stdio.h>
  2. #include        "c.h"
  3. #include        "expr.h"
  4. #include        "gen.h"
  5. #include        "cglbdec.h"
  6.  
  7. /*
  8.  *    68000 C compiler
  9.  *
  10.  *    Copyright 1984, 1985, 1986 Matthew Brandt.
  11.  *    all commercial rights reserved.
  12.  *
  13.  *    This compiler is intended as an instructive tool for personal use. Any
  14.  *    use for profit without the written consent of the author is prohibited.
  15.  *
  16.  *    This compiler may be distributed freely for non-commercial use as long
  17.  *    as this notice stays intact. Please forward any enhancements or questions
  18.  *    to:
  19.  *
  20.  *        Matthew Brandt
  21.  *        Box 920337
  22.  *        Norcross, Ga 30092
  23.  */
  24.  
  25. char            infile[20],
  26.                 listfile[20],
  27.                 outfile[20];
  28. extern TABLE    tagtable;
  29. int        mainflag;
  30. extern int      total_errors;
  31.  
  32. main(argc,argv)
  33. int     argc;
  34. char    **argv;
  35. {       while(--argc) {
  36.                 if( **++argv == '-')
  37.                         options(*argv);
  38.                 else if( openfiles(*argv)) {
  39.                         lineno = 0;
  40.                         initsym();
  41.                         getch();
  42.                         getsym();
  43.                         compile();
  44.                         summary();
  45.                         release_global();
  46.                         closefiles();
  47.                         }
  48.                 }
  49. }
  50.  
  51. int    options(s)
  52. char    *s;
  53. {    return 0;
  54. }
  55.  
  56. int     openfiles(s)
  57. char    *s;
  58. {       char    *p;
  59.         int     ofl, lfl;
  60.         strcpy(infile,s);
  61.         strcpy(listfile,s);
  62.         strcpy(outfile,s);
  63.         makename(listfile,".lis");
  64.         makename(outfile,".s");
  65.         if( (input = fopen(infile,"r")) == 0) {
  66.                 printf(" cant open %s\n",infile);
  67.                 return 0;
  68.                 }
  69.         ofl = creat(outfile,-1);
  70.         if( ofl < 0 )
  71.                 {
  72.                 printf(" cant create %s\n",outfile);
  73.                 fclose(input);
  74.                 return 0;
  75.                 }
  76.         if( (output = fdopen(ofl,"w")) == 0) {
  77.                 printf(" cant open %s\n",outfile);
  78.                 fclose(input);
  79.                 return 0;
  80.                 }
  81.         if( (list = fopen(listfile,"w")) == 0) {
  82.                 printf(" cant open %s\n",listfile);
  83.                 fclose(input);
  84.                 fclose(output);
  85.                 return 0;
  86.                 }
  87.         return 1;
  88. }
  89.  
  90. makename(s,e)
  91. char    *s, *e;
  92. {       while(*s != 0 && *s != '.')
  93.                 ++s;
  94.         while(*s++ = *e++);
  95. }
  96.  
  97. summary()
  98. {       printf("\n -- %d errors found.",total_errors);
  99.         fprintf(list,"\f\n *** global scope symbol table ***\n\n");
  100.         list_table(&gsyms,0);
  101.         fprintf(list,"\n *** structures and unions ***\n\n");
  102.         list_table(&tagtable,0);
  103. }
  104.  
  105. closefiles()
  106. {       fclose(input);
  107.         fclose(output);
  108.         fclose(list);
  109. }
  110.